package logic

import (
	"context"

	"go-zero-admin/apps/user/rpc/internal/svc"
	"go-zero-admin/apps/user/rpc/user"
	"go-zero-admin/pkg/errorx"

	"github.com/zeromicro/go-zero/core/logx"
)

type InfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
	return &InfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

//  登录信息
func (l *InfoLogic) Info(in *user.UserInfoReq) (*user.UserInfoResp, error) {
	userModel, err := l.svcCtx.SysUserModel.FindOne(l.ctx, in.UserId)
	if err != nil {
		return nil, errorx.NewDefaultError(errorx.ServerErrorCode)
	}

	return &user.UserInfoResp{
		Username: userModel.Username,
		Avatar:   userModel.Avatar,
	}, nil
}
